package com.jason.bookworm.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {
    private T data;
    private Integer code;
    private String msg;

    //只适用于无返回data的模板
    public static Result<Object> getResult(StatusEnum status){
        return new Result<>(status);
    }

    //只适用于无返回data的模板
    public static Result<Object> getResult(StatusEnum status,String msg){
        return new Result<>(status,msg);
    }

    public Result() {
    }

    public Result(StatusEnum status,T data) {
        this.data = data;
        this.code = status.getCode();
        this.msg=status.getMsg();
    }

    public Result(StatusEnum status){
        this.code=status.getCode();
        this.msg=status.getMsg();
    }

    public Result(StatusEnum status,T data,String msg){
        this.code=status.getCode();
        this.data=data;
        this.msg=msg;
    }

    public Result(StatusEnum status,String msg){
        this.code=status.getCode();
        this.msg=msg;
    }

    public Result(int code,T data,String msg){
        this.code=code;
        this.data=data;
        this.msg=msg;
    }

    public Result(int code,String msg){
        this.code=code;
        this.msg=msg;
    }
}
